'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 15_study_react_with_google.py
* @Time: 2025/11/3
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain import hub
from langchain.agents import create_react_agent, AgentExecutor
from langchain_community.tools import GoogleSerperRun
from langchain_community.utilities import GoogleSerperAPIWrapper
from langchain_core.tools import render_text_description_and_args
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field

dotenv.load_dotenv()
class GoogleSerperSchema(BaseModel):
    query:str = Field(description="执行谷歌搜索的查询语句")

google_serper = GoogleSerperRun(
    name = "google_serper",
    description = ("一个低成本的谷歌搜索API工具！"),
    args_schema=GoogleSerperSchema,
    api_wrapper=GoogleSerperAPIWrapper(),)
#2、定义工具列表
tools = [google_serper]
prompt = hub.pull("hwchase17/eact")


#3、创建大语言模型
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
agent = create_react_agent(
    llm=llm,
    tools=tools,
    prompt=prompt,
    tools_renderer=render_text_description_and_args
)

agnent_exxcuter = AgentExecutor(agent=agent, tools=tools, verbose=True)

print(agnent_exxcuter.invoke({"input":"你好"}))
